'''
Traits are granted to characters based on their race (or perhaps something else...)
and are generally modifiers applied directly by code checks when doing things
like eg. lighting checks for low-light vision.
'''

from xml.etree import ElementTree

traits = {}
def add_trait(klass):
    traits[klass.name] = klass

def from_xml(tag):
    '''Load the trait from an XML file.
    '''
    name = tag.get('name')
    return traits[name]()


class Trait(object):
    def to_xml(self, root):
        m = ElementTree.SubElement(root, 'trait', name=self.name)
        m.tail = '\n'

class LowLightVision(Trait):
    '''Grants extra perception under low-light conditions.
    '''
    name = 'low_light_vision'
add_trait(LowLightVision)

